
import express, { Request, Response, Router } from 'express';
import { puppeteerManager } from '../puppeteer-service';
import { LiveStreamManager } from '../LiveStreamManager';
const router: Router = express.Router();
router.use(express.json());

 
/**
 * 获取直播间信息
 */
router.get('/getLiveInfo', async (req: Request, res: Response) => {
    try {
      const { roomId } = req.query
      
      if (!roomId) {
        res.status(400).json({ error: '缺少roomId参数' });
        return;
      }

      const liveInfo = await puppeteerManager.getLiveInfo(roomId as string)
      res.json({ success: true, data: liveInfo })
    } catch (error) {
      console.error('获取直播间信息API错误:', error)
      res.status(500).json({ 
        success: false, 
        error: error instanceof Error ? error.message : '未知错误' 
      })
    }
  });
  /**
 * 连接直播间
 */
router.post('/connectLiveRoom', async (req: Request, res: Response) => {
  try {
    const { roomId } = req.body
    if (!roomId) {
      res.status(400).json({ error: '缺少roomId参数' });
      return;
    }
    const connection = await LiveStreamManager.startDanmuRecording(roomId);
    res.json({ success: true, data: connection, message: '连接成功' })
  } catch (error) {
    console.error('连接直播间API错误:', error)
    res.status(500).json({ 
      success: false, 
      error: error instanceof Error ? error.message : '未知错误' 
    })
  }
})

router.get("/", function(req: Request, res: Response){
  res.end("dycast");
})

export default router;